#include <iostream>
#include <stack>

using namespace std;

template<class T>
class BigNumber{
    long n;
public:
    BigNumber(T i)
    :n(i){
    }
    BigNumber operator+(BigNumber b){
        return BigNumber(n + b.n);
    }
};

void Test1(){
    int x;
    cin >> x;
    int a = 0, b = 1, c = 1;
    while (c < x){
        a = b;
        b = c;
        c = a + b;
    }
    int ret = min(abs(x-b), abs(c-x));
    cout << ret << endl;
}

class Parenthesis{
public:
    bool chkParenthesis(string A, int n){
        stack<char> st;
        for (int i = 0; i < n; ++i) {
            if (A[i] == '(')
                st.push(A[i]);
            else if (A[i] == ')'){
                if (st.empty() || st.top() != '(')
                    return false;
                else
                    st.pop();
            } else
                return false;
        }
        return st.empty();
    }
};

int main() {
    Test1();
    return 0;
}

